package com.qen.encrypt.utils;

import com.qen.encrypt.inter.ApiResponse;
import lombok.Builder;
import lombok.Data;

/**
 * @author licz
 * @data 2025年07月21日 10:34
 */
@Data
@Builder
public class DefaultResponse extends ApiResponse {

    private int code;
    private String message;
    private Object data;
    private int encrypt;

    @Override
    public int getCode() {
        return this.code;
    }

    @Override
    public String getMessage() {
        return this.message;
    }

    @Override
    public void setMessage(String message) {
        this.message = message;
    }

    @Override
    public Object getData() {
        return this.data;
    }

    @Override
    public void setData(Object data) {
        this.data = data;
    }

    @Override
    public void setEncrypt(int encrypt) {
        this.encrypt = encrypt;
    }


    public static ApiResponse ok() {
        return ok(null, "请求成功", 200);
    }

    public static ApiResponse ok(Object data) {
        return ok(data, "请求成功", 200);
    }

    public static ApiResponse ok(Object data, String message) {
        return ok(data, message, 200);
    }

    public static ApiResponse ok(Object data, String message, int code) {
        DefaultResponse response = DefaultResponse.builder()
                .code(code)
                .message(message)
                .data(data)
                .encrypt(1)
                .build();
        return response;
    }

    public static ApiResponse fail() {
        return fail("请求失败", 400);
    }

    public static ApiResponse fail(int code) {
        return fail("请求失败", code);
    }

    public static ApiResponse fail(String message, int code) {
        return DefaultResponse.builder().message(message).code(code).encrypt(0).build();
    }

}
